package com.ruoyi.ruoyiyinzheng.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.ruoyiyinzheng.domain.vo.StMaterialSupplierVo;
import com.ruoyi.ruoyiyinzheng.domain.bo.StMaterialSupplierBo;
import com.ruoyi.ruoyiyinzheng.service.IStMaterialSupplierService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 物料供应商控制器
 * 前端访问路由地址为:/ruoyiyinzheng/materialSupplier
 *
 * @author ruoyi
 * @date 2023-09-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/materialSupplier")
public class StMaterialSupplierController extends BaseController {

    private final IStMaterialSupplierService iStMaterialSupplierService;

    /**
     * 查询物料供应商列表
     */
    @SaCheckPermission("ruoyiyinzheng:materialSupplier:list")
    @GetMapping("/list")
    public TableDataInfo<StMaterialSupplierVo> list(StMaterialSupplierBo bo, PageQuery pageQuery) {
        return iStMaterialSupplierService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出物料供应商列表
     */
    @SaCheckPermission("ruoyiyinzheng:materialSupplier:export")
    @Log(title = "物料供应商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StMaterialSupplierBo bo, HttpServletResponse response) {
        List<StMaterialSupplierVo> list = iStMaterialSupplierService.queryList(bo);
        ExcelUtil.exportExcel(list, "物料供应商", StMaterialSupplierVo.class, response);
    }

    /**
     * 获取物料供应商详细信息
     *
     * @param supplierId 主键
     */
    @SaCheckPermission("ruoyiyinzheng:materialSupplier:query")
    @GetMapping("/{supplierId}")
    public R<StMaterialSupplierVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long supplierId) {
        return R.ok(iStMaterialSupplierService.queryById(supplierId));
    }

    /**
     * 新增物料供应商
     */
    @SaCheckPermission("ruoyiyinzheng:materialSupplier:add")
    @Log(title = "物料供应商", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StMaterialSupplierBo bo) {
        return toAjax(iStMaterialSupplierService.insertByBo(bo));
    }

    /**
     * 修改物料供应商
     */
    @SaCheckPermission("ruoyiyinzheng:materialSupplier:edit")
    @Log(title = "物料供应商", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StMaterialSupplierBo bo) {
        return toAjax(iStMaterialSupplierService.updateByBo(bo));
    }

    /**
     * 删除物料供应商
     *
     * @param supplierIds 主键串
     */
    @SaCheckPermission("ruoyiyinzheng:materialSupplier:remove")
    @Log(title = "物料供应商", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] supplierIds) {
        return toAjax(iStMaterialSupplierService.deleteWithValidByIds(Arrays.asList(supplierIds), true));
    }
}
